<?php

namespace App\Admin\Controllers;

use App\Models\Client;
use App\Models\Deduct;
use App\Models\Feedbacke;
use App\Http\Controllers\Controller;
use DemeterChain\A;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Show;
use App\Admin\Extensions\AddCash;
use App\Admin\Extensions\ClientConfig;
use App\Admin\Extensions\Feedback;

class FeedbackController extends Controller
{
    use HasResourceActions;

    /**
     * Index interface.
     *
     * @param Content $content
     * @return Content
     */
    public function index(Content $content)
    {
        return $content
            ->header('反馈管理')
            ->description('反馈管理')
            ->body($this->grid());
    }

    /**
     * Show interface.
     *
     * @param mixed $id
     * @param Content $content
     * @return Content
     */
    public function show($id, Content $content)
    {
        return $content
            ->header('反馈管理')
            ->description('反馈管理')
            ->body($this->detail($id));
    }

    /**
     * Edit interface.
     * @param mixed $id
     * @param Content $content
     * @return Content
     */
    public function edit($id, Content $content)
    {
        return $content
            ->header('资方管理')
            ->description('编辑操作')
            ->body($this->form()->edit($id));
    }

    /**
     * Create interface.
     *
     * @param Content $content
     * @return Content
     */
    public function create(Content $content)
    {
        return $content
            ->header('Create')
            ->description('description')
            ->body($this->add_form());
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Feedbacke);
        $grid->model()->where('tenant_id', '');
        $grid->id('Id');
        $grid->mobile('用户');
        $grid->feed('反馈');
        $grid->call('回复');
        $grid->created_at('创建时间');
        $grid->disableExport();
        $grid->disableRowSelector();
        $grid->disableFilter();
        $grid->actions(function ($actions) {
            $actions->disableDelete();
            $actions->disableView();
            $actions->disableEdit();
            $id = $actions->row->id;
            $name = $actions->row->mobile;
            $feed = '';
            $actions->append(new Feedback($id, $name, $feed));
        });
        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Client::findOrFail($id));

        $show->id('Id');
        $show->name('Name');
        $show->sign('Sign');
        $show->cash('Cash');
        $show->created_at('Created at');
        $show->updated_at('Updated at');

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Client);
        $form->text('name', '姓名');
        $form->text('client_url', '网址');
        $form->text('protocol', '网址协议');
        $form->text('sign', '唯一标识');
        $form->text('bsign', '风控唯一标识');
        $form->tools(function (Form\Tools $tools) {
            $tools->disableDelete();
            $tools->disableView();
        });

        $form->disableReset();
        $form->disableEditingCheck();
        $form->disableViewCheck();
        return $form;
    }

    protected function add_form(){
        $form = new Form(new Client);
        $form->text('name', '姓名');
        $form->text('client_url', '网址');
        $form->text('protocol', '网址协议');
        $form->text('sign', '唯一标识');
        $form->text('bsign', '风控唯一标识');
        $form->tools(function (Form\Tools $tools) {
            $tools->disableDelete();
            $tools->disableView();
        });
        $form->disableReset();
        $form->disableEditingCheck();
        $form->disableViewCheck();
        return $form;
    }
}
